package com.zsd.android.camerax.view.fragment

import android.content.Context
import android.net.Uri
import android.os.Bundle
import com.zsd.android.camerax.R
import com.zsd.android.common.BaseFragment
import com.zsd.android.common.BaseModel
import com.zsd.android.common.BasePresenter
import com.zsd.android.common.IBaseView

private const val ARG_PARAM1 = "param1"
private const val ARG_PARAM2 = "param2"

class MeFragment : BaseFragment<IBaseView, BaseModel<*>, BasePresenter<IBaseView, BaseModel<*>>>() {

    private var param1: String? = null
    private var param2: String? = null
    private var listener: OnFragmentInteractionListener? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        arguments?.let {
            param1 = it.getString(ARG_PARAM1)
            param2 = it.getString(ARG_PARAM2)
        }
    }

    fun onButtonPressed(uri: Uri) {
        listener?.onFragmentInteraction(uri)
    }

    override fun onAttach(context: Context) {
        super.onAttach(context)
        if (context is OnFragmentInteractionListener) {
            listener = context
        } else {
            throw RuntimeException(context.toString() + " must implement OnFragmentInteractionListener")
        }
    }

    override fun onDetach() {
        super.onDetach()
        listener = null
    }

    interface OnFragmentInteractionListener {
        fun onFragmentInteraction(uri: Uri)
    }

    companion object {

        @JvmStatic
        fun newInstance(param1: String, param2: String) =
            MeFragment().apply {
                arguments = Bundle().apply {
                    putString(ARG_PARAM1, param1)
                    putString(ARG_PARAM2, param2)
                }
            }
    }

    override fun layoutId(): Int {
        return R.layout.fragment_me
    }

    override fun initPresenter(): BasePresenter<IBaseView, BaseModel<*>>? {
        return null
    }

    override fun initView(savedInstanceState: Bundle?) {
    }
}
